package cn.acyou.leo.user.controller;

import cn.acyou.leo.framework.model.Result;
import cn.acyou.leo.user.entity.ProductVo;
import cn.acyou.leo.user.prop.AppProperty;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * @author fangyou
 * @version [1.0.0, 2021/7/29]
 */
@Slf4j
@RestController
@RequestMapping("/config")
@Api(value = "配置", tags = "配置接口")
@RefreshScope
public class ConfigController {
    @Autowired
    private AppProperty appProperty;

    @Value("${app-ext.name}")
    private String extName;

    @RequestMapping(value = "get", method = {RequestMethod.GET})
    @ApiOperation("获取配置")
    public Result<Object> get() {
        return Result.success(appProperty.getPrice());
    }
    @RequestMapping(value = "get2", method = {RequestMethod.GET})
    @ApiOperation("获取配置(测试Bigdecimal序列化)")
    public Result<ProductVo> get2() {
        ProductVo productVo = new ProductVo();
        productVo.setName("西红柿");
        productVo.setPrice(new BigDecimal(10.00));
        return Result.success(productVo);
    }

    @RequestMapping(value = "getExt", method = {RequestMethod.GET})
    @ApiOperation("获取扩展配置")
    public Result<Object> getExt() {
        return Result.success(extName);
    }

}
